﻿Imports System.Data.OleDb
Public Class AddAlbum
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_AddAlbum_Click(sender As Object, e As EventArgs) Handles btn_AddAlbum.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BeachConnectionString").ConnectionString)
        Dim SqlString As String = "INSERT INTO Albums(Tourist, AlbumName, Description, DateAdded) VALUES (@f1, @f2, @f3, Now())"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f2", tb_AlbumName.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Description.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        'Find id of the new album.
        Dim getLastIdCmd As OleDbCommand = New OleDbCommand("SELECT TOP 1 ID FROM Albums ORDER BY ID DESC", oleDbConn)
        Dim dr = getLastIdCmd.ExecuteReader()
        dr.Read()
        Dim lastId = dr.GetValue(0)
        oleDbConn.Close()
        Response.Redirect(String.Format("AddPicturesToAlbum.aspx?Album={0}", lastId))
    End Sub

    Protected Sub btn_Cancel_Click(sender As Object, e As EventArgs) Handles btn_Cancel.Click
        Response.Redirect(String.Format("Profile.aspx?Tourist={0}", User.Identity.Name))
    End Sub
End Class